package edu.ycxy.poetry.controller;


import com.github.pagehelper.PageInfo;
import edu.ycxy.poetry.entity.DjInfo;
import edu.ycxy.poetry.service.IDjInfoService;
import edu.ycxy.poetry.vo.UpdateDjVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author @xin
 * @createDate 2022/3/14
 * @Description
 */
@RestController
@RequestMapping("/djInfo")
@Slf4j
public class DjInfoController {

    @Autowired
    private IDjInfoService djInfoService;


    //根据古籍的章节目录的id查询该目录里面的详细内容
    @RequestMapping("/content/{id}")
    public DjInfo findContentById(@PathVariable("id") Integer id){
        return djInfoService.findContentById(id);
    }

    @RequestMapping("/find/fuzzy/{title}")
    public PageInfo<DjInfo> findFuzzy(@PathVariable String title,Integer pageNum){
        if (pageNum == null){
            pageNum = 1;
        }
        PageInfo<DjInfo> fuzzy = djInfoService.findFuzzy(title, pageNum, 5);
        return fuzzy;
    }

    @GetMapping("/delete/{id}")
    public void deleteDjById(@PathVariable Integer id){
        djInfoService.deleteDjInfoById(id);
    }

    @GetMapping("/findOne/{id}")
    public DjInfo findOneById(@PathVariable Integer id){
        //log.debug("获取的信息：" + djInfoService.findContentById(id));
        return djInfoService.findContentById(id);
    }

    @PostMapping("/update")
    public void updateDjInfo(@RequestBody UpdateDjVo updateDjVo){
        log.debug("获取的vo信息：" + updateDjVo);
        djInfoService.updateDjInfo(updateDjVo);
    }
}
